<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <script>
      let res = prompt('true或者false')
      function getColorRadios(flag = true) {
        if (flag) {
          //true执行这句话
          //每次随机在数组里面抽取一个 然后通过拼接字符串的方式来获取随机数
          let str = '#'
          let arr = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f',]
          for (let i = 1; i <= 6; i++) {
            let sum = Math.floor(Math.random() * arr.length)
            str += arr[sum]
          }
          return str
        } else {
          //false执行这句话
          let r = Math.floor(Math.random() * 266)
          let g = Math.floor(Math.random() * 266)
          let b = Math.floor(Math.random() * 266)
          return `rgb(${r},${g},${b})`
        }
      }
      document.write(
        ` <div style="width: 200px; height: 200px; background-color:${getColorRadios(
          res
        )};"></div>`
      )
    </script>
  </body>
</html>
